new Vue({
    el: '#app',
    data() {
        return {
            expressCompany:[],
            
            sales_order_logistics: [
                {
        
                  disabled1: false,  // 禁用物流公司
                  Sales_Order_Logistics_SerialNumber: '', //主键
                  Sales_Order_SerialNumber: '',   //销售价格单号 
                  LogisticsNumbers: '',  //物流单号
                  LogisticsCode: '',  //快递公司
                  Quantity: '',   //数量
                }
              ],
            form: {
                Sales_Receipt_SerialNumber: '',//主键
                Receipt_Date: '',//出库日期
                Receipt_Type: "0",//出货地点
                Receipt_Name: "",
                Store_SerialNumber: "",//仓库编号
                Store_Name: "",
                Enterprise_Info_SerialNumber: "",//企业主键
                Children: {
                    sales_receipt_detail: [
                        {
                            Sales_Receipt_Detail_SerialNumber: "",//主键
                            Sales_Receipt_SerialNumber: "",//外键
                            Order_Type: "1",//订单类型
                            Sales_Order_SerialNumber: "",//销售订单流水号
                            Article_SerialNumber: "",//商品流水号
                            Article_Name: "",
                            Receipt_Quantity: "",//出库数量
                            // Amount:"",//商品单价
                            Order_Name: "",
                            Logistics_Number: "",//物流单号
                        }
                    ]
                }
            },
            purchaseOrderData: {},
            salesOrderData: {}, 
            formData: {},
            loading: false,
            disabled: true,
        }
    },
    computed: {
       
         
      },
    mounted() {
      
        let abc=decodeURIComponent(window.location.search).split('=')[decodeURIComponent(window.location.search).split('=').length-1];
        let a = JSON.parse(abc)
        console.log('1111111111111111',a); // 输出: paramValue
        this.formData = a
        console.log('本地存储',this.formData)
        this.form.Receipt_Date = getYMDHMSDate()
        this.form.Receipt_Type == '0' ? this.form.Receipt_Name = '仓库' : this.form.Receipt_Name = '店铺'
        this.form.Children.sales_receipt_detail[0].Order_Type == '1' ? this.form.Children.sales_receipt_detail[0].Order_Name = '企业' : this.form.Children.sales_receipt_detail[0].Order_Name = '用户'
        this.form.Store_Name = this.formData.Warehouse_Name//
         this.form.Children.sales_receipt_detail[0].Sales_Order_SerialNumber = this.formData.Purchase_Order_SerialNumber
        this.form.Children.sales_receipt_detail[0].Article_Name = this.formData.Article_Name
        this.form.Children.sales_receipt_detail[0].Receipt_Quantity = this.formData.Delivery_Quantity
        if (this.formData.Purchase_Order_SerialNumber.indexOf("M") != -1) {
            this.purchaseOrder(this.formData.Purchase_Order_SerialNumber)
        } else {
            this.salesOrder(this.formData.Purchase_Order_SerialNumber)
        }
       
        if (this.form.Children.sales_receipt_detail.length != 0) {
            this.disabled = false
        }
        this.getCompany()
    },
  
    methods: {
       
        submitForm() {
            if (this.form.Children.sales_receipt_detail[0].Logistics_Number== '') {
                this.$message({
                    message: '请填写物流单号',
                    type: 'error'
                });
                return
            }
            let _this = this
            _this.loading = true
            _this.form.Receipt_Type = '0'
            _this.form.Children.sales_receipt_detail[0].Order_Type = '1'
            _this.form.Store_SerialNumber = this.formData.Warehouse_SerialNumber
            _this.form.Children.sales_receipt_detail[0].Article_SerialNumber = this.formData.Article_SerialNumber
            console.log('form',_this.form)
            console.log('物流单号',_this.form.Children.sales_receipt_detail[0].Logistics_Number)
            console.log('物流公司',_this.sales_order_logistics[0].LogisticsCode)
            $.ajax({
                type: 'GET',
                url: BASE_URL +'/Order/setReduceInventoryAction', 
                data:{
                    'token':$.cookie('token'),
                    'Delivery_Order_SerialNumber':_this.formData.Delivery_Order_SerialNumber,
                    'Logistics_Code':_this.sales_order_logistics[0].LogisticsCode,
                    'Logistics_Number':_this.form.Children.sales_receipt_detail[0].Logistics_Number
                },
                success: function (res) {
                    console.log('11111111111111111111111111',res)
                    if (res.status == 0) {
                      _this.loading = false
                      window.history.go(-1)
                    }else{
                        _this.loading = false
                        _this.$message.error(res.Cause)
                    }
                },
                complete: function (XMLHttpRequest) {
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = absolutepath + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                dataType: "json"
            });
        },
        purchaseOrder(Primary_Key) {
            console.log(Primary_Key)
            let _this = this
            $.ajax({
                type: 'POST',
                url: DomainName + "/getInquiryIDOriginal?token=" + $.cookie("token"),
                data: {
                    Primary_Key_Name: 'Purchase_Order_SerialNumber',
                    Primary_Key,
                    Data: 'purchase_order',
                    isNullEnterprise: true
                },
                success: function (res) {
                    console.log(res)
                    _this.purchaseOrderData = res[0]
                },
                complete: function (XMLHttpRequest) {
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = absolutepath + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                dataType: "json"
            });
        },
        salesOrder(Primary_Key) {
            console.log(Primary_Key)
            let _this = this
            $.ajax({
                type: 'POST',
                url: DomainName + "/getInquiryIDOriginal?token=" + $.cookie("token"),
                data: {
                    Primary_Key_Name: 'Sales_Order_Detail_SerialNumber',
                    Primary_Key,
                    Data: 'sales_order_detail',
                    isNullEnterprise: true
                },
                success: function (res) {
                    console.log(res)
                    _this.salesOrderData = res[0]
                },
                complete: function (XMLHttpRequest) {
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = absolutepath + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                dataType: "json"
            });
        },
        getCompany() {
            $.ajax({
              type: 'POST',
              url: `${DomainName}/getInquiryAction?token=${$.cookie('token')}`,
              data: {
                Data: 'logistics_company_info',
                isNullEnterprise: true
              },
              success: (data) => {
                this.expressCompany = data
                console.log('物流公司',this.expressCompany)
              },
              complete: (XMLHttpRequest) => {
                this.loading = false
                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                  window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                }
              },
              dataType: "json"
            });
          },
    },
})